﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using SQLH2ConfigTool.Util;

namespace SQLH2ConfigTool
{
    public partial class frmAddServer : Form
    {
        private ConfigurationFile cf;
        public frmAddServer(ConfigurationFile cf)
        {
            this.cf = cf;
            InitializeComponent();
        }

        public string ServerName
        {
            get { return txtServer.Text; }
        }

        private void btnAddServer_Click(object sender, EventArgs e)
        {
            ValidateServer();
        }

        private void ValidateServer()
        {
            //check the server does not exist.
            foreach (Server s in cf.Servers)
            {
                if (s.ServerName == txtServer.Text)
                {
                    MessageBox.Show(txtServer.Text + " already exists in the configuration file");
                    return;
                }
            }

            PingUtil p = new PingUtil();
            if (!p.PingServer(txtServer.Text))
            {
                MessageBox.Show("Unable to Contact Server");
                return;
            }
            this.DialogResult = DialogResult.OK;
        }
    }
}
